﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShopPanel : BasePanel
{
    public Transform content;

    private void Start()
    {
        //得到关闭按钮 监听点击事件 点击后关闭自己商店面板即可
        GetControl<Button>("btnClose").onClick.AddListener(() =>
        {
            UIManager.GetInstance().HidePanel("ShopPanel");
        });
    }


    public override void ShowMe()
    {
        base.ShowMe();
        //显示商店面板时，初始化商店面板中的售卖信息
        //根据商店数据来进行初始化
        for (int i = 0; i < GameDataMgr.GetInstance().shopInfos.Count; i++)
        {
            //实例化一个商店物品信息UI组合控件
            ShopCell cell = ResMgr.GetInstance().Load<GameObject>("UI/ShopCell").GetComponent<ShopCell>();
            //设置父对象
            cell.transform.SetParent(content);
            //设置相对缩放大小 避免显示出错
            cell.transform.localScale = Vector3.one;
            //传商店售卖物品信息给他，让他进行更新
            cell.InitInfo(GameDataMgr.GetInstance().shopInfos[i]);
        }
    }
}
